package ynu.beggar.server.entities.PO;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import ynu.beggar.server.entities.DO.BulletinDO;

import javax.persistence.*;
import java.sql.Timestamp;
import java.time.LocalDateTime;

@Entity
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "bulletin", schema = "ynu_beggar")
public class BulletinPO {
    private int bulletinId;
    private String text;
    private String pictureUrl;
    private Timestamp createTime;
    private Integer del;

    public BulletinPO(BulletinDO bulletinDO) {
        this.text = bulletinDO.getText();
        this.pictureUrl = bulletinDO.getPictureUrl();
        this.createTime = Timestamp.valueOf(LocalDateTime.now());
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "bulletin_id")
    public int getBulletinId() {
        return bulletinId;
    }

    public void setBulletinId(int bulletinId) {
        this.bulletinId = bulletinId;
    }

    @Basic
    @Column(name = "text")
    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    @Basic
    @Column(name = "picture_url")
    public String getPictureUrl() {
        return pictureUrl;
    }

    public void setPictureUrl(String pictureUrl) {
        this.pictureUrl = pictureUrl;
    }

    @Basic
    @Column(name = "create_time")
    public Timestamp getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Timestamp createTime) {
        this.createTime = createTime;
    }

    @Basic
    @Column(name = "del")
    public Integer getDel() {
        return del;
    }

    public void setDel(Integer del) {
        this.del = del;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        BulletinPO bulletinPO = (BulletinPO) o;

        if (bulletinId != bulletinPO.bulletinId) return false;
        if (text != null ? !text.equals(bulletinPO.text) : bulletinPO.text != null) return false;
        if (pictureUrl != null ? !pictureUrl.equals(bulletinPO.pictureUrl) : bulletinPO.pictureUrl != null) return false;
        if (createTime != null ? !createTime.equals(bulletinPO.createTime) : bulletinPO.createTime != null) return false;
        if (del != null ? !del.equals(bulletinPO.del) : bulletinPO.del != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = bulletinId;
        result = 31 * result + (text != null ? text.hashCode() : 0);
        result = 31 * result + (pictureUrl != null ? pictureUrl.hashCode() : 0);
        result = 31 * result + (createTime != null ? createTime.hashCode() : 0);
        result = 31 * result + (del != null ? del.hashCode() : 0);
        return result;
    }
}
